package com.dmy.vo.helper;

import com.dmy.vo.FriendListVo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;

/**
 * create by huahuadelei for 2020/1/12
 */
public class ZDYGroupHandler implements FriendListGroupHandler {
    private final Map<String,List<FriendListVo>> groupMap;

    public ZDYGroupHandler() {
        this.groupMap = new TreeMap<String,List<FriendListVo>>((k1,k2)-> k1.compareToIgnoreCase(k2));
    }

    @Override
    public void push(FriendListVo friendListVo) {
                                            // 当key不存在 才会执行表达式中的代码 （创建一个list，再获取出来）
        List<FriendListVo> friendListVos = groupMap.computeIfAbsent(friendListVo.getCharCase(), c -> new ArrayList<FriendListVo>());
        friendListVos.add(friendListVo);
    }

    @Override
    public Map<String, List<FriendListVo>> groupResult() {
        return groupMap;
    }
}
